home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Source / Dialog Item Stuff / SkelDlogMapKey.c < prev    next >
Text File  |  1996-01-17  |  3KB  |  104 lines

  1. /*
  2.  * SkelDlogMapKeyToButton ()
  3.  *
  4.  * This routine looks at an event to see whether or not it's a key event
  5.  * that should be mapped onto an item hit in a dialog's default or cancel
  6.  * button.
  7.  *
  8.  * defaultItem is 0 if no return/enter mapping should be done, > 0 to
  9.  * explicitly specify the item that return/enter map to, < 0 to map
  10.  * return/enter to the item specified as the default in the dialog record.
  11.  *
  12.  * cancelItem is 0 if no escape/cmd-period mapping should be done, > 0 to
  13.  * explicitly specify the item that escape/cmd-period map to.
  14.  *
  15.  * If the key maps to a button item, the button is flashed for visual
  16.  * feedback if it is hilited normally (not dimmed).  If the button is enabled,
  17.  * the item parameter is set to the item number and the function returns true.
  18.  * If the key doesn't map to an item or the button is disabled, the function
  19.  * returns false.
  20.  *
  21.  * If the key maps to a button, but the button isn't hilited properly or is
  22.  * disabled, the event is mapped to a null event so that nothing else is done
  23.  * with it.  This is done based on the assumption that if the caller is trying
  24.  * to do key mapping, it doesn't want the mapped keys to get into dialog edit
  25.  * text items.
  26.  */
  27.  
  28. # include    "TransSkel.h"
  29.  
  30.  
  31. # define    returnKey    13
  32. # define    enterKey    3
  33. # define    escapeKey    27
  34.  
  35.  
  36. # define    normalHilite    0
  37. # define    dimHilite        255
  38.  
  39.  
  40. /*
  41.  * Function that checks whether a dialog item is a button.  If so,
  42.  * flash it.  In addition, if it's active, return true to indicate an
  43.  * item hit.  Otherwise return false.
  44.  */
  45.  
  46. static Boolean
  47. TestDlogButton (DialogPtr d, short item)
  48. {
  49. ControlHandle    ctrl;
  50. Handle    itemHandle;
  51. short    itemType;
  52. Rect    itemRect;
  53.  
  54.     GetDialogItem (d, item, &itemType, &itemHandle, &itemRect);
  55.     if ((itemType & (ctrlItem + btnCtrl)) == (ctrlItem + btnCtrl))
  56.     {
  57.         ctrl = (ControlHandle) itemHandle;
  58.         if ((**ctrl).contrlHilite == normalHilite)
  59.         {
  60.             SkelFlashButton (ctrl);
  61.             if ((itemType & itemDisable) == 0)
  62.                 return (true);
  63.         }
  64.     }
  65.     return (false);
  66. }
  67.  
  68.  
  69. pascal Boolean
  70. SkelDlogMapKeyToButton (DialogPtr dlog, EventRecord *evt, short *item,
  71.                                 short defaultItem, short cancelItem)
  72. {
  73. char    c;
  74. short    i;
  75.  
  76.     c = evt->message & charCodeMask;
  77.     if (c == returnKey || c == enterKey)
  78.     {
  79.         i = defaultItem;
  80.         if (i != 0)
  81.         {
  82.             if (i < 0)
  83.                 i = ((DialogPeek) dlog)->aDefItem;
  84.             if (TestDlogButton (dlog, i))
  85.             {
  86.                 *item = i;
  87.                 return (true);
  88.             }
  89.             evt->what = nullEvent;
  90.         }
  91.     }
  92.     if (c == escapeKey || SkelCmdPeriod (evt))
  93.     {
  94.         *item = cancelItem;
  95.         if (*item > 0)
  96.         {
  97.             if (TestDlogButton (dlog, *item))
  98.                 return (true);
  99.             evt->what = nullEvent;
  100.         }
  101.     }
  102.     return (false);
  103. }
  104.